/*
 * Copyright (C) 2010 SJTU IST Lab., All Rights Reserved.
 */
package sjtu.ist.warehouse4ws.dynamicDS;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;


/**
 * @author Steve Jin
 * @version 1.0
 */

public class MetadataExport {
	public static final String exportpath="E:/Workspaces/MyEclipse/WareHouse4WS/db/tablexml/";
	//导出
	public static void exportxml (String tablename){
		String user = "warehouse"; //用户名
		String pwd = "warehouse"; //密码
		String host = "localhost"; //主机
		//String oper = "-d"; //是否需要数据
		String exdb = "warehouse4ws"; //导出数据库名
		String extable = tablename; //导出表名
		String path = exportpath; //文件存放路径
		//String imdb = "warehouse4ws_cust"; //导入数据库名
		try{
			String MySql="mysqldump --xml -u"+user+" -p"+pwd+" -h"+host+" -d "+exdb+" "+extable+" > "+path+extable+".xml";   
			java.lang.Runtime.getRuntime().exec("cmd /c "+MySql);  
			System.out.println("exportxml success!");
		}
		catch (Exception e){
			e.printStackTrace();
		}
	}
	
	private static void exportsql (String config[]){
		String user = "root"; //用户名
		String pwd = "123456"; //密码
		String host = "localhost"; //主机
		//String oper = "-d"; //是否需要数据
		String exdb = "warehouse4ws"; //导出数据库名
		String extable = "user"; //导出表名
		String path = "./"; //文件存放路径
		String imdb = "warehouse4ws_cust"; //导入数据库名
		try{
			String MySql="mysqldump -u"+user+" -p"+pwd+" -h"+host+" -d "+exdb+" "+extable+" > "+path+extable+".sql";     
			java.lang.Runtime.getRuntime().exec("cmd /c "+MySql);  
			System.out.println("exportsql success!");
		}
		catch (Exception e){
			e.printStackTrace();
		}
	}

	
	
	//导入
	private static void importsql (String config[]){
		try{   
			String path = "mysql "+config[0]+" "+config[1]+" "+config[2]+" "+config[7]+" < "+config[6]+config[5]+".sql";     
			java.lang.Runtime.getRuntime().exec("cmd /c "+path);  
			System.out.println("importsql success!");
		}
		catch (Exception e){
			e.printStackTrace();
		}
		}
	
	private static void importxml (String config[]){
		try{   
			String path = "mysql "+config[0]+" "+config[1]+" "+config[2]+" "+config[7]+" < "+config[6]+config[5]+".xml";     
			java.lang.Runtime.getRuntime().exec("cmd /c "+path);  
			System.out.println("importxml success!");
		}
		catch (Exception e){
			e.printStackTrace();
		}
		}


	
}
